<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!-- 搜索 -->
      <el-input v-model="query.productName" placeholder="請輸入產品名稱" style="width: 220px;margin-bottom: 20px" />
      <el-input v-model="query.sku" placeholder="請輸入產品編號" style="width: 220px;margin-bottom: 20px" />
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation>
        <template #right>
          <el-button
            class="filter-item"
            size="mini"
            type="warning"
            :disabled="!crud.selections.length > 0"
            @click="exportExpire"
          >導出
          </el-button>
          <rrOperation :crud="crud" />
        </template>
      </crudOperation>
      <!--表格渲染-->
      <el-table
        ref="table"
        v-loading="crud.loading"
        row-key="id"
        :data="crud.data"
        stripe
        style="width: 100%;"
        @selection-change="crud.selectionChangeHandler"
      >
        <el-table-column type="selection" width="55" />
        <el-table-column prop="expireDate" label="過期時間" />
        <el-table-column prop="productName" label="產品名稱" width="300"/>
        <el-table-column prop="sku" label="	產品編號" />
        <el-table-column prop="upc" label="	upc" />
        <el-table-column prop="productCategory" label="產品種類" />
        <el-table-column prop="vendor" label="供应商" width="200"/>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudReport from '@/api/fms/report'
import CRUD, { presenter, header, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
import { mapGetters } from 'vuex'
import { downloadFile } from '@/utils'

export default {
  name: 'Expire',
  components: { pagination, crudOperation, rrOperation },
  mixins: [presenter(), header(), crud()],
  dicts: ['true_false'],
  cruds() {
    return CRUD({
      title: '入库单商品预警时间报表',
      url: 'report/expire',
      sort: [],
      crudMethod: { ...crudReport },
      optShow: {}
    })
  },
  data() {
    return {
      modelEndDate: [],
      timeSlot: ''
    }
  },
  computed: {
    ...mapGetters(['imagesUploadApi', 'baseApi'])
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    exportExpire() {
      crudReport.exportExpire().then(res => {
        if (res.code !== undefined && res.code !== 0) {
          this.$notify({
            title: '失敗',
            message: res.message,
            type: 'error'
          })
          return
        }
        downloadFile(res, this.crud.title + '数据', 'xlsx')
      })
    },
    getTimeSlot(sel) {
      this.query.startTime = sel[0]
      this.query.endTime = sel[1]
      this.crud.toQuery()
    }
  }
}
</script>

<style scoped>

</style>
